<?php
/*
 * Created on Nov 13, 2007
 * File: TemplateController.php
 * Project: BIMP
 * Author: jerrad
 */
 
  //require the includes php file one directory up
 require_once(dirname(dirname(__FILE__)). DIRECTORY_SEPARATOR."includes.php");

 class TemplateController{
 	
 	static public function CreateDefaultSmartyObject(){
 	global $CFG;
	
 		$smarty = new Smarty();
		
		$smarty->template_dir = $CFG->smarty_template_dir;
		$smarty->compile_dir  = $CFG->smarty_compile_dir;
		$smarty->config_dir   = $CFG->smarty_config_dir;
		$smarty->cache_dir    = $CFG->smarty_cache_dir;
			
		//Couple of default varialbes to assign	
		$smarty->assign("Title", "barcode inventory management system");
	    $smarty->assign("Web_Path_To_Template_dir", $CFG->Web_Path_To_Template_dir);
	 
		return $smarty;
 	}
 	
 	static private function CreateMainNavigationMenu(array $menuItems, $currentPage = null){
 		
 		if(count($menuItems) == 0){
 			throw new Exception("Array was empty");
 		} 		
 		
 		$html = "";
 		
 		foreach($menuItems as $key => $value){
 			if($key == $currentPage){
 				$html .= "<li class=\"current_page_item\"><a href=\"".$value."\">".$key."</a></li>";
 			}else{
 				$html .= "<li><a href=\"".$value."\">".$key."</a></li>";
 			}
 			
 		} 		 	
		
		return $html;
 	}
 	
 	static private function SetMainNavigationItems(){
 		
    global $CFG;
    
    $link = $CFG->web_site_root;
    $menuItems = array("Homepage"  => $link . "index.php", 
                       "Inventory" => $link . "inventory.php", 
					   "Shopping"  => $link . "shopping.php", 
                       "Reporting" => $link . "reporting.php", 
                       "Recipes"   => $link . "recipes.php");  
                       
      return $menuItems;
 	}
 	
 	

    static public function MainNavigationMenu($smarty, $currentPage){
     //Get menu Items
	 //In the future I hope these menu items will be dynamic
	 
	 
	 $menuItems = TemplateController::SetMainNavigationItems();
	 $MenuItemHtml = TemplateController::CreateMainNavigationMenu($menuItems, $currentPage);
	 
	 $smarty->assign("Main_Navigation", $MenuItemHtml);
	 
    }
 }
?>
